package org.easyexcel.Server;

import org.easyexcel.Server.Interface.BookStore;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

public class prarseAnno {

    @Test
    public void test() {
        //从类中获取注解
        Class<Book> bookClass = Book.class;
        //判断类中是否有注解
        if (bookClass.isAnnotationPresent(BookStore.class)) {
            //获取注解对象
            BookStore bookStore = bookClass.getDeclaredAnnotation(BookStore.class);
            String name = bookStore.name();
            float price = bookStore.price();
            String[] author = bookStore.author();
            System.out.println(name + " " + price + " " + author[0] + " " + author[1] + " " + author[2]);
        }
    }
    public static void test1(Object obj) throws Exception {
        //从成员方法中获取注解
        Method method = obj.getClass().getMethod("buybook");
        if (method.isAnnotationPresent(BookStore.class)) {
            BookStore bookStore = method.getAnnotation(BookStore.class);
            String name = bookStore.name();
            float price = bookStore.price();
            String[] authors = bookStore.author();

            System.out.println(name + " " + price + " " + authors[0] + " " + authors[1] + " " + authors[2]);
        }

    }
}
